package DieSiedler;
/*
 * HandelsResourcen.java
 *
 * Created on 3. Mai 2007, 17:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import javax.swing.*;
import java.awt.*;
/**
 *
 * @author Michi
 */
public class HandelsResourcen extends JPanel{
    private String name;
    private boolean isEditable = true;
    private int holz, weizen, wolle, erz, lehm;
    private JLabel holzLabel, weizenLabel, wolleLabel, erzLabel, lehmLabel;
    private JTextField holzText, weizenText, wolleText, erzText, lehmText;
    
    /** Creates a new instance of HandelsResourcen */
    public HandelsResourcen(String name, int holz, int weizen, int wolle, int erz, int lehm) {
        this.holz   = holz;
        this.weizen = weizen;
        this.wolle  = wolle;
        this.erz    = erz;
        this.lehm   = lehm;

        this.setBorder(BorderFactory.createTitledBorder(name));
        
        holzLabel = new JLabel("Holz");
        holzLabel.setSize(60,25);
        holzLabel.setLocation(20,40);
        add(holzLabel);
        
        holzText = new JTextField(Integer.toString(holz));
        holzText.setHorizontalAlignment(JTextField.RIGHT);
        holzText.setSize(60,25);
        holzText.setLocation(80,40);
        add(holzText);
        
        lehmLabel = new JLabel("Lehm");
        lehmLabel.setSize(60,25);
        //lehmLabel.setLocation(20,200);
        lehmLabel.setLocation(20,80);
        add(lehmLabel);
        
        lehmText = new JTextField(Integer.toString(lehm));
        lehmText.setHorizontalAlignment(JTextField.RIGHT);
        lehmText.setSize(60,25);
        //lehmText.setLocation(80,200);
        lehmText.setLocation(80,80);
        add(lehmText);

        weizenLabel = new JLabel("Weizen");
        weizenLabel.setSize(60,25);
        //weizenLabel.setLocation(20,80);
        weizenLabel.setLocation(20,120);
        add(weizenLabel);
        
        weizenText = new JTextField(Integer.toString(weizen));
        weizenText.setHorizontalAlignment(JTextField.RIGHT);
        weizenText.setSize(60,25);
        //weizenText.setLocation(80,80);
        weizenText.setLocation(80,120);
        add(weizenText);
        
        wolleLabel = new JLabel("Wolle");
        wolleLabel.setSize(60,25);
        //wolleLabel.setLocation(20,120);
        wolleLabel.setLocation(20,160);
        add(wolleLabel);
        
        wolleText = new JTextField(Integer.toString(wolle));
        wolleText.setHorizontalAlignment(JTextField.RIGHT);
        wolleText.setSize(60,25);
        //wolleText.setLocation(80,120);
        wolleText.setLocation(80,160);
        add(wolleText);
        
        erzLabel = new JLabel("Stein");
        erzLabel.setSize(60,25);
        //erzLabel.setLocation(20,160);
        erzLabel.setLocation(20,200);
        add(erzLabel);
        
        erzText = new JTextField(Integer.toString(erz));
        erzText.setHorizontalAlignment(JTextField.RIGHT);
        erzText.setSize(60,25);
        //erzText.setLocation(80,160);
        erzText.setLocation(80,200);
        add(erzText);
        
    }
    
    public void setEditable(boolean isEditable){
        this.isEditable = isEditable;
        holzText.setEditable(isEditable);
        weizenText.setEditable(isEditable);
        wolleText.setEditable(isEditable);
        erzText.setEditable(isEditable);
        lehmText.setEditable(isEditable);
    }
    
    public int getHolzValue(){
    	int val = 0;
    	try{
    		val = Integer.parseInt(holzText.getText());
    	}catch(Exception e){
    		
    	}
        return val;
    }
    
    public int getWeizenValue(){
    	int val = 0;
    	try{
    		val = Integer.parseInt(weizenText.getText());
    	}catch(Exception e){
    		
    	}
        return val;
    }
    
    public int getWolleValue(){
    	int val = 0;
    	try{
    		val = Integer.parseInt(wolleText.getText());
    	}catch(Exception e){
    		
    	}
        return val;
    }
    
    public int getErzValue(){
    	int val = 0;
    	try{
    		val = Integer.parseInt(erzText.getText());
    	}catch(Exception e){
    		
    	}
        return val;
    }
    
    public int getLehmValue(){
    	int val = 0;
    	try{
    		val = Integer.parseInt(lehmText.getText());
    	}catch(Exception e){
    		
    	}
        return val;
    }
    
    public void setHolzValue(int holz){
        holzText.setText(Integer.toString(holz));
    }
    
    public void setWeizenValue(int weizen){
        weizenText.setText(Integer.toString(weizen));
    }
    
    public void setWolleValue(int wolle){
        wolleText.setText(Integer.toString(wolle));
    }
    
    public void setErzValue(int erz){
        erzText.setText(Integer.toString(erz));
    }
    
    public void setLehmValue(int lehm){
        lehmText.setText(Integer.toString(lehm));
    }
    
    public void setGegenspielerName(String name){
        this.setBorder(BorderFactory.createTitledBorder(name));
    }
    
}
